$(function(){
    removeStudentDormCheckbox=function(){
        removeList=new Array();
        $(":checkbox[name='grade_major_checkbox']:checked").each(function(index,e){
            grade=$(this).parents("tr").find(".grade").html();
            major=$(this).parents("tr").find(".major_id").html();
            classs=$(this).parents("tr").find(".class").html();
            student_allocated=$(this).parents("tr").find(".student_allocated").html();
            if(student_allocated>0){
                remove=new Object();
                remove.grade=grade;
                remove.major=major;
                remove.class=classs;
                removeList[index]=remove;
            }else{
                $(this).prop("checked",false);
            }
            
        });
        if(removeList.length>0){
            removeJSON=JSON.stringify(removeList);
            layer.confirm("确定清空选中的班级住宿信息",{btn:['确定','取消']},
            function(){
                $.post("/php/class-dormitory-management.php",{action:3,data:removeJSON},
                function(result){
                    resultObj=JSON.parse(result);
                    //alert(result);
                    switch(resultObj.code){
                        case '2001':
                        layer.msg(resultObj.message,{btn:['确定'],icon:1},
                        function(){
                            location.replace(location.href);
                        });
                        break;
                        case '2002':
                        layer.msg(resultObj.message);
                        break;
                        case '2003':
                        layer.msg(resultObj.message);
                        break;
                        case '2004':
                        layer.msg(resultObj.message);
                        break;
                        default:
                        layer.msg(resultObj.message);
                        break;
                    }
                });
            });
        }else{
            layer.msg("未选中任何项");
        }
    }

    removeDormitory=function(table){
        removeList=new Array();
        remove=new Object();
        remove.grade=$(table).parents("tr").find(".grade").html();
        remove.major=$(table).parents("tr").find(".major_id").html();
        remove.class=$(table).parents("tr").find(".class").html();
        removeList[0]=remove;

        student_allocated=$(table).parents("tr").find(".student_allocated").html();
        if(student_allocated>0){
            removeJSON=JSON.stringify(removeList);
            layer.confirm("确定清空选中的班级住宿信息",{btn:['确定','取消']},
            function(){
                $.post("/php/class-dormitory-management.php",{action:3,data:removeJSON},
                function(result){
                    resultObj=JSON.parse(result);
                    //alert(result);
                    switch(resultObj.code){
                        case '2001':
                        layer.msg(resultObj.message,{btn:['确定'],icon:1},
                        function(){
                            location.replace(location.href);
                        });
                        break;
                        case '2002':
                        layer.msg(resultObj.message);
                        break;
                        case '2003':
                        layer.msg(resultObj.message);
                        break;
                        case '2004':
                        layer.msg(resultObj.message);
                        break;
                        default:
                        layer.msg(resultObj.message);
                        break;
                    }
                });
            });
        }else{
            layer.msg('不需要清空');
        }
    }
});